home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / dvptame.zip / DVPTAME.ASM next >
Assembly Source File  |  1991-04-26  |  4KB  |  193 lines

  1. ;**************************************************************************
  2. ;*                                      *
  3. ;*  DVPTAME      Tame keyboard polls by patching .DVP              *
  4. ;*  Donated to the Public Domain by Ralf Brown, 4/27/91           *
  5. ;*                                      *
  6. ;*  (This is a modified and expanded version of the DVPWIDTH program      *
  7. ;*       distributed with RBcomm)                      *
  8. ;*                                      *
  9. ;**************************************************************************
  10.  
  11. code    segment
  12.     assume    cs:code,ds:code,es:code,ss:code
  13.     org    80h
  14. cmdline_len db    ?
  15. cmdline     db    127 dup (?)
  16.  
  17.         org     100h
  18.  
  19. dvptame:
  20.     mov    cl,cmdline_len
  21.     xor    ch,ch
  22.     mov    si,offset cmdline
  23.     mov    dx,offset usage_msg
  24.     jcxz    exit_with_msg
  25.     call    skip_whitespace
  26.     cmp    al,'='                 ; display current setting only?
  27.     je    number_done           ; if yes, skip parsing the number
  28.     mov    display_only,0
  29. ; collect the digits of the number
  30. number_loop:
  31.     sub    al,'0'
  32.     jb    exit_with_msg
  33.     cmp    al,9
  34.     ja    exit_with_msg
  35.     cbw                   ; zero AH
  36.     mov    bx,ax
  37.     mov    al,10
  38.     mul    polls
  39.     add    ax,bx
  40.     mov    polls,ax
  41.     lodsb
  42.     dec    cx
  43.     jcxz    exit_with_msg
  44.     cmp    al,' '
  45.     je    number_done
  46.     cmp    al,9
  47.     jne    number_loop
  48. number_done:
  49. ; scan off leading whitespace
  50.     call    skip_whitespace
  51. ; skip to end of filename and terminate with NUL
  52.     mov    dx,si
  53.     dec    dx            ; DS:DX -> start of filename
  54.     push    dx            ; remember filename pointer
  55. filename_loop:
  56.     lodsb
  57.     dec    cx
  58.     jcxz    terminate_filename
  59.     or    al,al
  60.     je    terminate_filename
  61.     cmp    al,' '
  62.     ja    filename_loop
  63.     dec    si            ; we went one character too far
  64. terminate_filename:
  65.     mov    byte ptr [si],0
  66.     pop    si            ; get back ptr to start of filename
  67. ; try to open file for reading
  68.     mov    al,00h            ; mode is read
  69.     call    open_file        ; SI -> filename, ret BX = handle
  70.     call    display_curr_polls
  71.         cmp     display_only,0
  72.     jne    exit
  73. ; finally, try to open file for writing
  74.     mov    al,01h
  75.     call    open_file
  76. ; if seek successful, write the new word
  77.     mov    ah,40h
  78.     mov    cx,2            ; write two bytes
  79.     mov    dx,offset polls
  80.     int    21h
  81.     mov    dx,offset write_error_msg
  82.     jc    exit_with_msg
  83. ; close file
  84.     mov    ah,3Eh
  85.     int    21h
  86. ; give success message
  87.     mov    dx,offset success_msg
  88. exit_with_msg:
  89.     mov    ah,9
  90.     int    21h
  91. exit:
  92.     mov    ax,4C00h
  93.     int    21h
  94.  
  95. open_file proc near
  96.         mov     dx,si                   ; DS:DX -> filename
  97.     mov    ah,3Dh
  98.     int    21h
  99.     mov    dx,offset open_error_msg
  100.     jc    exit_with_msg
  101.     mov    bx,ax
  102. ; if open successful, seek to offset 175h (max_polls)
  103.     mov    ax,4200h
  104.     xor    cx,cx
  105.     mov    dx,0175h
  106.     int    21h
  107.     mov    dx,offset seek_error_msg
  108.         jc      exit_with_msg
  109.     ret
  110. open_file endp
  111.  
  112. skip_whitespace proc near
  113.     lodsb
  114.     dec    cx            ; have we run out of input?
  115.     jcxz    exit_with_msg        ; DX still points at usage_msg
  116.         or      al,al
  117.     je    exit_with_msg
  118.     cmp    al,13
  119.     je    exit_with_msg
  120.     cmp    al,' '
  121.     je    skip_whitespace
  122.     cmp    al,9
  123.     je    skip_whitespace
  124.     ret
  125. skip_whitespace endp
  126.  
  127. display_curr_polls proc near
  128.     push    bx            ; preserve file handle
  129.         mov     ax,4200h
  130.     xor    cx,cx
  131.     mov    dx,0175h        ; seek to "tame" word in .DVP
  132.     int    21h
  133.     mov    cx,2            ; read a word
  134.     mov    dx,offset curr_polls
  135.     mov    ah,3Fh
  136.     int    21h
  137.     mov    ax,curr_polls
  138.     mov    bx,offset number_buf
  139.     xor    di,di
  140.         mov     cx,10
  141. itoa_loop:
  142.     xor    dx,dx
  143.     idiv    cx
  144.     add    dl,'0'
  145.     mov    [bx+di],dl
  146.     inc    di
  147.     or    ax,ax
  148.     jne    itoa_loop
  149.     mov    cx,di
  150.     shr    cx,1
  151.     jcxz    itoa_done
  152.         dec     di
  153.     push    si
  154.     xor    si,si
  155. itoa_rev:
  156.     mov    al,[bx+si]
  157.     xchg    al,[bx+di]
  158.     mov    [bx+si],al
  159.     inc    si
  160.     dec    di
  161.     loop    itoa_rev
  162.     pop    si
  163. itoa_done:
  164.     pop    bx            ; recover file handle
  165.     mov    ah,3Eh            ; close file
  166.     int    21h
  167.     mov    dx,offset max_polls_msg
  168.     mov    ah,9
  169.     int    21h
  170.     ret
  171. display_curr_polls endp
  172.  
  173. polls        dw 0
  174. curr_polls    dw ?
  175. display_only    db 1
  176. usage_msg    db "DVPTAME",9,9,"Tame keyboard polls via .DVP",13,10
  177.         db "Donated to the Public Domain by Ralf Brown",13,10,10
  178.         db "Usage:  DVPTAME polls dvp-file",13,10
  179.         db 9,"where 'polls' is a number indicating how many keyboard",13,10
  180.         db 9,"polls to allow in one clock tick (0 = infinite)",13,10
  181.         db "$"
  182. max_polls_msg    db "Current maximum polls = "
  183. number_buf    db "     "
  184.         db 13,10,"$"
  185. success_msg     db "Maximum polls set",13,10,"$"
  186. open_error_msg    db "Error opening .DVP file",13,10,"$"
  187. seek_error_msg    db "Seek on .DVP file failed",13,10,"$"
  188. write_error_msg db "Write to .DVP file failed",13,10,"$"
  189.  
  190. code ends
  191.      end dvptame
  192.  
  193.